package com.leihao.marketing.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leihao.common.core.exception.ServiceException;
import com.leihao.marketing.domain.ListRequest;
import com.leihao.marketing.domain.Preference;
import com.leihao.marketing.mapper.PreferenceMapper;
import com.leihao.marketing.mapper.SubjectMapper;
import com.leihao.marketing.service.PreferenceService;
import com.leihao.marketing.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PreferenceServiceImpl implements PreferenceService {
    @Autowired
    private PreferenceMapper preferenceMapper;
    @Override
    public void add(Preference preference) {
        preferenceMapper.add(preference);
    }

    @Override
    public void delete(Integer preferenceId) {
            if (preferenceId == null){
                throw new ServiceException("删除编号不能为空!");
            }
            preferenceMapper.delete(preferenceId);
    }

    @Override
    public PageInfo<Preference> findList(ListRequest listRequest) {
        PageHelper.startPage(listRequest.getPageNum(),listRequest.getPageSize());
        List<Preference> list = preferenceMapper.findList();
        PageInfo<Preference> preferencePageInfo = new PageInfo(list);
        return preferencePageInfo;
    }

    @Override
    public Preference findById(Integer preferenceId) {
        if (preferenceId == null){
            throw new ServiceException("查询编号不能为空!");
        }
        return preferenceMapper.findById(preferenceId);
    }

    @Override
    public void update(Preference preferenceId) {
        if (preferenceId.getPreferenceId() == null){
            throw new ServiceException("修改编号不能为空!");
        }
        preferenceMapper.update(preferenceId);
    }

    @Override
    public List<Preference> findAll() {
        return preferenceMapper.findAll();
    }
}
